<template>
  <view class="deviceimgList">
    <view
      class="picture"
      v-if="pics.length > 0"
    >
      <view class="left"> 我上传的图片: </view>
      <view class="right">
        <view
          class="feedback-image-item"
          v-for="(item, index) in pics"
          :key="index"
        >
          <view class="image-box">
            <image
              :src="item.url"
              mode="aspectFill"
              @tap="previewImg(item.url)"
            ></image>
          </view>
        </view>
      </view>
    </view>
    <view
      class="no-devicelist"
      v-if="pics.length <= 0"
    >
      <image
        src="https://mkservice.mk-iot.com/subFile/mk2240/no-device.png"
        alt=""
      />
      <text>暂无图片</text>
    </view>
  </view>
</template>

<script>
  import {
    getMyUploadImgList,
    getEquipmentIdImg,
  } from '@/api/system/equiment/equipment.js'
  import config from '@/config'
  const baseUrl = config.baseUrl
  export default {
    data() {
      return {
        deviceDetail: '',
        equipmentNo: uni.getStorageSync('equipmentNo'),
        type: 'center',
        pics: [],
        imglist: [],
        queryImgList: {
          pageNum: 1,
          pageSize: 10,
          deviceId: null,
        },
      }
    },
    onLoad() {
      this.getdeviceUploadImglist()
    },
    methods: {
      getdeviceUploadImglist: async function () {
        this.queryImgList.deviceId = this.equipmentNo
        const res = await getMyUploadImgList(this.queryImgList)
        if (res.code == 200) {
          uni.stopPullDownRefresh()
          res.rows.forEach((item, index) => {
            //处理小程序多选状况
            this.pics.push({
              url: config.baseUrl + item.filePath,
            })
          })
        }
      },
      //浏览图片
      previewImg(url) {
        const thant = this
        this.imglist = []
        //放到图片列表里可以查询
        this.pics.forEach((item, index) => {
          thant.imglist.push(item.url)
        })
        uni.previewImage({
          urls: thant.imglist,
          current: url,
          // 下面我这边做的都是默认的选择
          longPressActions: {
            itemList: ['发送给朋友', '保存图片', '收藏'],
            success: function (data) {
              thant.$modal.msgSuccess(data)
            },
            fail: function (err) {
              thant.$modal.msgError(err)
            },
          },
        })
      },
      //下拉事件
      onPullDownRefresh() {
        this.pics = []
        this.getdeviceUploadImglist()
      },
    },
  }
</script>

<style lang="scss">
  page {
    background-color: #f9f9f9;
  }

  .deviceimgList {
    width: 100%;
    overflow: hidden;
    box-sizing: border-box;
    padding: 0 20rpx;
  }

  .picture {
    width: 100%;
    overflow: hidden;
    background: #fff;
  }

  .picture .left {
    width: 300rpx;
    padding-top: 20rpx;
    font-size: 36rpx;
    font-weight: bold;
  }

  .picture .right {
    display: flex;
    flex-wrap: wrap;
    padding: 20rpx;

    .feedback-image-item {
      position: relative;
      width: 33.33%;
      height: 0;
      padding-top: 33.33%;
      box-sizing: border-box;

      .image-box {
        display: flex;
        justify-content: center;
        align-items: center;
        position: absolute;
        top: 10rpx;
        right: 10rpx;
        left: 10rpx;
        bottom: 10rpx;
        border: 1px #c7c7c7 solid;
        border-radius: 10rpx;
        overflow: hidden;

        image {
          width: 100%;
          height: 100%;
        }
      }
    }
  }

  .no-devicelist {
    display: flex;
    flex-direction: column;
    text-align: center;
    align-items: center;
    justify-content: center;
    font-size: 36rpx;
  }

  .no-devicelist > image {
    margin-top: 200rpx;
    width: 200rpx;
    height: 200rpx;
  }

  .no-devicelist > text {
    margin-top: 20rpx;
  }
</style>
